<?php
/**@var \Weline\Framework\View\Template $this */
/**@var \Weline\Backend\Block\ThemeConfig $themeConfig */
$themeConfig = \Weline\Framework\Manager\ObjectManager::getInstance(\Weline\Backend\Block\ThemeConfig::class);
?>
<!DOCTYPE html>
<!--
 *@Author       秋枫雁飞
 *@Email        aiweline@qq.com
 *@Forum        https://bbs.aiweline.com
 *@DESC         后台共用头部
-->
<html lang='en' <?= ('rtl' === $themeConfig->getThemeModel()) ? " dir=\"rtl\"" : '' ?>>

<head>
    @template(Weline_Admin::common/head.phtml)
    <!-- jquery.mCustomScrollbar 插件 -->
    <link href="@static(Weline_Admin::/libs/jquery.mCustomScrollbar/jquery.mCustomScrollbar.css)" rel="stylesheet"/>
    <!-- Responsive Table css -->
    <link href='@static(Weline_Admin::assets/libs/admin-resources/rwd-table/rwd-table.min.css)' rel='stylesheet'
          type='text/css'/>
    <link href='@static(Weline_Eav::css/attribute.css)' rel='stylesheet' type='text/css'/>
    <!-- Sweet Alert-->
    <link href='@static(Weline_Admin::assets/libs/sweetalert2/sweetalert2.min.css)' rel='stylesheet' type='text/css'/>
    <title><?= __('Weline Admin 管理面板') ?></title>
</head>

<body <?= $themeConfig->getLayouts() ?? ''; ?>>

<!--页头工具条 开始-->
@template(Weline_Admin::common/page/loading.phtml)
<!--页头工具条 结束-->

<!-- <body data-layout="horizontal" data-topbar="dark"> -->

<!-- 开始 页面 -->
<div id="layout-wrapper">


    <!--页头工具条 开始-->
    <w:block class='Weline\Admin\Block\Backend\Page\Topbar'/>
    <!--页头工具条 结束-->

    <!-- ========== Topnav Start ========== -->
    <!--页头菜单栏 开始-->
    <w:block class='Weline\Admin\Block\Backend\Page\Topnav'/>
    <!--页头菜单栏 结束-->

    <!-- ========== Left Sidebar Start ========== -->
    <!--左侧菜单栏 开始-->
    @template(Weline_Admin::common/left-sidebar.phtml)
    <!--左侧菜单栏 结束-->


    <!-- ============================================================== -->
    <!-- Start right Content here -->
    <!-- ============================================================== -->
    <div class="main-content">

        <div class='page-content'>
            <div class='container-fluid'>
                <!-- start page title -->
                <div class='row'>
                    <div class='col-12'>
                        <div class='page-title-box d-sm-flex align-items-center justify-content-between'>
                            <h4 class='mb-sm-0'>
                                <lang>Eav>属性管理</lang>
                            </h4>

                            <div class='page-title-right'>
                                <ol class='breadcrumb m-0'>
                                    <li class='breadcrumb-item'><a href='javascript: void(0);'>
                                            <lang>系统配置</lang>
                                        </a></li>
                                    <li class='breadcrumb-item'><a href="@backend-url('*/backend/attribute')">
                                            <lang>Eav</lang>
                                        </a>
                                    </li>
                                    <li class='breadcrumb-item'>
                                        <a href="@backend-url('*/backend/attribute')">
                                            <lang>属性</lang>
                                        </a>
                                    </li>
                                </ol>
                            </div>

                        </div>
                    </div>
                </div>
                <!-- end page title -->
                <!-- start page message -->
                <div class='row'>
                    <template>Weline_Component::message.phtml</template>
                </div> <!-- end message -->
                <div class='row'>
                    <div class='col-12'>
                        <div class='card'>
                            <div class='card-body'>
                                <h4 class='card-title'>
                                    <lang>Eav实体-属性管理</lang>
                                </h4>
                                <p class='card-title-desc'>
                                    <lang>管理实体的属性</lang>
                                    <notempty name="entity">
                                        <lang>您当前管理的属性实体是：</lang>
                                        <span class="text-info">{{entity.name}}</span>
                                    </notempty>
                                </p>
                                <div class='table-rep-plugin'>
                                    <!-- search form -->
                                    <div class='row'>
                                        <div class='col-6'>
                                            <block class='Weline\Component\Block\Form\Search'
                                                   id='entity-attribute-search' action='*/backend/attribute'
                                                   method='get' keyword='search' value=''
                                                   placeholder='请输入属性关键词回车搜索'>
                                            </block>
                                        </div>
                                        <div class='col-6'>
                                            <block class="Weline\Component\Block\OffCanvas"
                                                   template="Weline_Component::off-canvas.phtml"
                                                   title="添加属性"
                                                   cache="0"
                                                   id="create_attr_off_canvas_new"
                                                   action="*/backend/attribute/add"
                                                   target-tag="button"
                                                   icon="mdi mdi-plus"
                                                   submit-button-text="保存"
                                                   submit-button-class="btn btn-primary"
                                                   target-button-text="添加"
                                                   target-button-class="btn btn-primary"
                                                   flush-button-text="刷新"
                                                   flush-button-class="btn btn-default"
                                                   flush="1"
                                                   save="1"
                                                   save-form="#attr-form"
                                                   close-button-show="1"
                                                   close-button-text="取消"
                                                   direction="right"
                                                   class-names="w-75"
                                                   off-canvas-body-style=""
                                            />
                                        </div>
                                    </div>
                                    <!-- end search form -->
                                    <div class='table-responsive mb-0' data-pattern='priority-columns'>
                                        <table id='tech-companies-1' class='table table-striped table-bordered'>
                                            <thead>
                                            <tr>
                                                <th data-priority='1'>
                                                    <lang>ID</lang>
                                                </th>
                                                <th data-priority='3'>
                                                    <lang>实体ID</lang>
                                                </th>
                                                <th data-priority='3'>
                                                    <?= __('代码') ?>
                                                </th>
                                                <th data-priority='3'>
                                                    <?= __('名称') ?>
                                                </th>
                                                <th data-priority='1'>
                                                    <?= __('启用') ?>
                                                </th>
                                                <th data-priority='3'>
                                                    <?= __('创建时间') ?>
                                                </th>
                                                <th data-priority='3'>
                                                    <?= __('更新时间') ?>
                                                </th>
                                                <th data-priority='3'>
                                                    <?= __('操作') ?>
                                                </th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <foreach name="attributes" item="attribute" key="key">
                                                <tr>
                                                    <td class='co-name'>{{attribute.attribute_id}}</td>
                                                    <td class='co-name'>
                                                        ID:{{attribute.eav_entity_id|0}}-{{attribute.entity_local_name|attribute.entity_name}}
                                                    </td>
                                                    <td>{{attribute.code}}</td>
                                                    <td class='co-name'>
                                                        <local
                                                                model="Weline\Eav\Model\EavAttribute\LocalDescription"
                                                                field="name" id="attribute.attribute_id"
                                                                name="attribute-name">
                                                            {{attribute.local_name|attribute.name}}
                                                        </local>
                                                    </td>
                                                    <td class='co-name'>
                                                        <if condition="attribute.is_enable"><span
                                                                    class="text-success">启用</span>
                                                            <else/>
                                                            <span class="text-danger">禁用</span>
                                                        </if>
                                                    </td>
                                                    <td class='co-name'>{{attribute.create_time}}</td>
                                                    <td class='co-name'>{{attribute.update_time}}</td>
                                                    <td class='co-name'>
                                                        <div class="d-flex gap-2">
                                                            <empty name="attribute.is_system">
                                                                <if condition="attribute.is_system == 0">
                                                                    <block class='Weline\Component\Block\OffCanvas'
                                                                           template='Weline_Component::off-canvas.phtml'
                                                                           cache='0' id='off_canvas_attribute_edit'
                                                                           action="*/backend/attribute/edit"
                                                                           vars="attribute"
                                                                           save="0"
                                                                           action-params="{attribute_id: attribute.attribute_id, eav_entity_id: attribute.eav_entity_id,isAjax:attribute.attribute_id}"
                                                                           target-button-text='修改'
                                                                           target-button-class='btn btn-info'
                                                                           title='编辑属性'
                                                                           close-button-show='1'
                                                                           close-button-text='关闭'
                                                                           direction='right' class-names='w-75'
                                                                           off-canvas-body-style=''/>
                                                                </if>
                                                                <a class="btn btn-danger ajax-delete"
                                                                   data-href="@backend-url('*/backend/attribute/delete', ['id'=>$attribute['attribute_id']])">
                                                                    <lang>删除</lang>
                                                                </a>
                                                                <else/>
                                                                <b class="text-danger">
                                                                    <lang>系统实体</lang>
                                                                </b>
                                                            </empty>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </foreach>
                                            </tbody>
                                        </table>
                                        {{pagination}}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div> <!-- end col -->
                </div> <!-- end row -->
            </div> <!-- container-fluid -->
        </div>
        <!-- End Page-content -->
    </div>
    <!-- end main content-->

</div>
<!-- END layout-wrapper -->
<!--右边栏-->
@template(Weline_Admin::common/right-sidebar.phtml)

<!-- Table Editable plugin -->
<script src="@static(Weline_Admin::assets/libs/table-edits/build/table-edits.min.js)"></script>
<script src="@static(Weline_Admin::assets/js/pages/menus/table-editable.init.js)"></script>
<script src='@static(Weline_Admin::/libs/jquery.mCustomScrollbar/jquery.mCustomScrollbar.concat.min.js)'></script>
<!-- Responsive Table js -->
<script src='@static(Weline_Admin::assets/libs/admin-resources/rwd-table/rwd-table.min.js)'></script>

<!-- Init js -->
<script src='@static(Weline_Admin::assets/js/pages/table-responsive.init.js)'></script>
<!-- 配置项弹窗 -->
<div id='optionConfig' class='modal fade' tabindex='-1' aria-labelledby='#optionConfig' aria-hidden='true'>
    <div class='modal-dialog modal-xl'>
        <div class='modal-content'>
            <div class='modal-header'>
                <h5 class='modal-title' id='optionConfigLabel'>
                    <lang>属性配置项弹窗</lang>
                </h5>
                <button type='button' class='btn-close' data-bs-dismiss='modal' aria-label='@lang{关闭}'></button>
            </div>
            <div class='modal-body'>
                <h5>配置属性的配置项</h5>
                <div>
                    <table>
                        <thread>
                            <th>代码</th>
                            <th>配置项</th>
                            <th>所属实体代码</th>
                            <th>创建时间</th>
                            <th>更新时间</th>
                            <th>操作</th>
                        </thread>

                        <tbody id="attributeOption">

                        </tbody>
                    </table>
                </div>
            </div>
            <div class='modal-footer'>
                <button type='button' class='btn btn-light waves-effect' data-bs-dismiss='modal'>
                    <lang>关闭</lang>
                </button>
                <button type='button' class='btn btn-primary waves-effect waves-light'>
                    <lang>保存更改</lang>
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<!-- Sweet Alerts js -->
<script src='@static(Weline_Admin::assets/libs/sweetalert2/sweetalert2.min.js)'></script>
<script>
    $('#optionConfig').on('show.bs.modal', function (event) {
        showLoading();
        // 触发的按钮
        let button = event.relatedTarget
        let attribute_code = button.getAttribute('data-code')
        let eav_entity_id = button.getAttribute('data-eav_entity_id')
        $.ajax({
            url: '@backend-url("*/backend/attribute/option/search")?eav_entity_id={eav_entity_id}&attribute_code={attribute_code}'
                .replace('{eav_entity_id}', eav_entity_id).replace('{attribute_code}', attribute_code),
            success: (res) => {
                let attributeOption = $('#attributeOption')
                attributeOption.empty()
                let options = res['option']
                if (options) {
                    for (let option in options) {
                        console.log()
                        attributeOption.append()
                    }
                }
                attributeOption.append('')
                console.log(res)
            }
        })
        hideLoading();
    })
    $('.ajax-delete').on('click', function () {
        Swal.fire({
            title: '<lang>确认删除</lang>',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: '<lang>确认</lang>',
            cancelButtonText: '<lang>取消</lang>',
            reverseButtons: true
        }).then((result) => {
            if (result.isConfirmed) {
                showLoading();
                $.ajax({
                    url: $(this).data('href'),
                    success: (res) => {
                        if (res['code'] == 1) {
                            Swal.fire({
                                title: '<lang>删除成功</lang>',
                                icon: 'success',
                                timer: 2000,
                                confirmButtonColor: '#3085d6',
                                confirmButtonText: '<lang>确认</lang>',
                            }).then(res => {
                                location.reload()
                            })
                        }
                        hideLoading();
                    }
                })
            }
        })
    })
</script>
<!-- 配置项弹窗 -->
@template(Weline_Admin::common/footer.phtml)
</body>

</html>